<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo13</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.js"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script>

    //用props只能一级一级接收，当代码量多的时候会非常的冗余
    //可以用provide创建变量
    //在需要的任意后代组件，用inject直接接收就能使用，非常方便
    const app = Vue.createApp({
        provide:{
        newHouse:'北京200平方房子一套'
    },
        template: `
            <div>我有一套房子，我先传给我的儿子</div>
            <child :house="house" />
         `
    })

    app.component('child',{
        props:['house'],
        template:`
            <div>我是子组件，我要把房子再传给我儿子。</div>
            <div>儿子接收{{house}}</div>
            <child-child :house="house" />
        `
    })

    app.component('child-child',{
        props:['house'],
        inject:['newHouse'],
        template:`
            <div>我是孙子，等待接收房子</div>
            <div>孙子接收{{house}}</div>
        `
    })
    const vm = app.mount("#app")
</script>